package cn.shyouchi.wuguanjia.android.ui.statistic;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.api.attendance.AttendanceApi;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.model.BaseRequestResult;
import cn.shyouchi.wuguanjia.android.subscribers.ProgressSubscriber;
import cn.shyouchi.wuguanjia.android.widget.TopBar;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class NewlyStaffActivity extends BaseActivity {

    @BindView(R.id.topBar)
    TopBar mTopBar;
    @BindView(R.id.rv_statistic_list)
    RecyclerView mRvStatisticList;


    NewlyStaffAdapter mNewlyStaffAdapter;

//    YearStatisticEntity.ResultMessageBean.RecruitsBeanX entity;
//
//    YearStatisticEntity.NumberBean.RecruitsBean entityYear;

    List<NewlyInfo> mEntities = new ArrayList<>();

    AttendanceApi mAttendanceApi;

    String date;
    String projectid;
    boolean isYear;


    @Override
    public int initContentView() {
        return R.layout.activity_newly_staff;
    }

    @Override
    public void initInjector() {
        date = getIntent().getStringExtra("date");
        mAttendanceApi = new AttendanceApi(mContext);
        isYear = getIntent().getBooleanExtra("year", false);

        projectid = getIntent().getStringExtra("projectid");

//        entity = getIntent().getParcelableExtra("newly");
//
//        entityYear = getIntent().getParcelableExtra("newly_year");
//
//        if (entity != null) {
//            mEntities.addAll(entity.getInfo());
//        }
//        if (entityYear != null) {
//            mEntities.addAll(entityYear.getInfo());
//        }



    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setTitle(getTitle().toString());
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(mTopBar.getToolbar());

        mNewlyStaffAdapter = new NewlyStaffAdapter(mEntities);
        mRvStatisticList.setAdapter(mNewlyStaffAdapter);
        mRvStatisticList.setLayoutManager(new LinearLayoutManager(mContext));
        mNewlyStaffAdapter.setEmptyView(LayoutInflater.from(mContext).inflate(R.layout.empty_view_layout, null));


        fetchMonthNewlyData();

    }


    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }



    private void fetchMonthNewlyData() {
        mAttendanceApi.getMothNewlyStaff(date, isYear,projectid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber<BaseRequestResult<List<NewlyInfo>>>(mContext) {
                    @Override
                    public void onNext(BaseRequestResult<List<NewlyInfo>> result) {
                        mEntities.clear();
                        mEntities.addAll(result.getResultMessage());
                        mNewlyStaffAdapter.notifyDataSetChanged();
                    }
                });
    }

}
